import request from '../request'
import requestUrl from '../requestUrl'
import requestParam from '../requestParam'
import isInteger from 'lodash/isInteger'

// 获取小程序种类
export function getMiniAppKind () {
  return request({
    url: requestUrl('/miniapp/type'),
    method: 'get',
    data: requestParam()
  })
}
// 获取用户信息
export function getUserInfo () {
  return request({
    url: requestUrl('/miniapp/user/info'),
    method: 'get',
    data: requestParam()
  })
}
// 修改用户名称
export function updateUserName (params) {
  return request({
    url: requestUrl('/miniapp/user/name'),
    method: 'post',
    data: requestParam(params, 'post', false)
  })
}
// 修改用户密码
export function updatePassword (params) {
  return request({
    url: requestUrl('/miniapp/user/password'),
    method: 'post',
    data: requestParam(params, 'post', false)
  })
}
// 获取小程序列表
export function getMiniAppList (params) {
  return request({
    url: requestUrl('/miniapp/list'),
    method: 'get',
    params: requestParam(params, 'get')
  })
}
// 通过产品ID获取产品价格
export function getPriceById (id) {
  return request({
    url: requestUrl('/miniapp/getpricebyid' + (isInteger(id) ? `/${id}` : '')),
    method: 'get',
    params: requestParam({}, 'get')
  })
}

// 小程序详情
export function createMiniapp (params) {
  return request({
    url: requestUrl('/miniapp/create'),
    method: 'post',
    data: requestParam(params)
  })
}

// 获取创建小程序的类别
export function getCAppInfo (params) {
  return request({
    url: requestUrl('/miniapp/kindinfos'),
    method: 'get',
    data: requestParam(params)
  })
}

// 获取小程序
export function getStatus () {
  return request({
    url: requestUrl(`/version/get_status`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 获取小程序主要版本信息
export function getMainData () {
  return request({
    url: requestUrl(`/version/get_main`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 获取小程序主要版本信息
export function getVersionData () {
  return request({
    url: requestUrl(`/version/get_version`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 获取小程序体验者二维码
export function getQrCodeUrl () {
  return requestUrl(`/version/get_qr_code`)
}
// 获取小程序体验者列表
export function getTestData () {
  return request({
    url: requestUrl(`/version/get_test`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 获取小程序二维码
export function getMainQrCode () {
  return requestUrl(`/version/get_main_code`)
}
// 绑定小程序
export function bindingTest (wechatId) {
  return request({
    url: requestUrl(`/version/binding_test?wechatId=` + wechatId),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 解除绑定小程序
export function unbindingTest (wechatId) {
  return request({
    url: requestUrl(`/version/unbinding_test?wechatId=` + wechatId),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 授权小程序
export function bind () {
  return request({
    url: requestUrl(`/version/bind`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 解除授权
export function unbind () {
  return request({
    url: requestUrl(`/version/unbind`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 审核撤回
export function undoCodeAudit () {
  return request({
    url: requestUrl(`/version/undo_code_audit`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 发布代码
export function release () {
  return request({
    url: requestUrl(`/version/release`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 提交审核代码
export function submitAudit () {
  return request({
    url: requestUrl(`/version/submit_audit`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 上传代码
export function commit () {
  return request({
    url: requestUrl(`/version/commit`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
// 获取小程序
export function getAuthUrl () {
  return request({
    url: requestUrl(`/open/auth/goto_auth_url`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}

// 获取sidebar菜单列表,暂时写在本地
export function sideMenuList (params) {
  const appMenuListJson = {
    'micro-station': [
      {
        list: [
          {
            menuId: '1-1',
            title: '数据概况',
            icon: '',
            routeName: 'ms-overview-data'
          }
        ],
        menuId: '1',
        title: '概况',
        icon: 'iconfont icon-overview'
      },
      {
        menuId: '2',
        title: '文章',
        icon: 'iconfont icon-book',
        list: [
          {
            menuId: '2-1',
            title: '文章管理',
            icon: '',
            routeName: 'ms-article-info-index'
          },
          {
            menuId: '2-2',
            title: '文章分类管理',
            icon: '',
            routeName: 'ms-article-category-index'
          },
          {
            menuId: '2-3',
            title: '公告信息',
            icon: '',
            routeName: 'ms-notice-info-index'
          }
        ]
      },
      {
        menuId: '3',
        title: '案例',
        icon: 'iconfont icon-casefile',
        list: [
          {
            menuId: '3-1',
            title: '案例管理',
            icon: '',
            routeName: 'ms-case-info-index'
          },
          {
            menuId: '3-2',
            title: '产品管理',
            icon: '',
            routeName: 'ms-product-index'
          }
        ]
      },
      {
        menuId: '4',
        title: '企业',
        icon: 'iconfont icon-enterprise',
        list: [
          {
            menuId: '4-1',
            title: '企业信息管理',
            icon: '',
            routeName: 'ms-company-info-index'
          },
          {
            menuId: '4-2',
            title: '加入我们',
            icon: '',
            routeName: 'ms-recrui-info-index'
          }
        ]
      },
      {
        menuId: '5',
        title: '表单',
        icon: 'iconfont icon-formmenu',
        routeName: 'ms-form-info-index'
      },
      {
        menuId: '6',
        title: '装修',
        icon: 'iconfont icon-swatche',
        routeName: 'ms-decoration'
      },
      // {
      //   menuId: '7',
      //   title: '插件',
      //   icon: 'iconfont icon-plug-in',
      //   routeName: 'micro-station-plugin'
      // },
      {
        menuId: '8',
        title: '版本',
        icon: 'iconfont icon-version',
        routeName: 'ms-version'
      // },
      // {
      //   menuId: '9',
      //   title: '设置',
      //   icon: 'iconfont icon-setting',
      //   routeName: 'micro-station-setting'
      }
    ]
  }
  return {
    'code': 0,
    'result': {
      'length': 4,
      'items': (params && params.type) ? appMenuListJson[params.type] : []
    }
  }
}

//
export function shopMallMenu (params) {
  return {
    'code': 0,
    'result': {
      'length': 4,
      'items': [
        {
          list: [
            {
              menuId: '1-1',
              title: '数据概况',
              icon: '',
              routeName: 'shop-mall-overview-data'
            }
          ],
          menuId: '1',
          title: '概况',
          icon: 'iconfont icon-overview'
        },
        {
          menuId: '2',
          title: '广告',
          icon: 'iconfont icon-enterprise',
          routeName: 'shop-mall-sh-advert'
        },
        {
          menuId: '3',
          title: '会员',
          icon: 'iconfont icon-book',
          list: [
            {
              menuId: '3-1',
              title: '会员管理',
              icon: '',
              routeName: 'shop-mall-sh-user'
            }
            // {
            //   menuId: '3-1-1',
            //   title: '会员等级',
            //   isHide: true,
            //   icon: '',
            //   routeName: 'shop-mall-sh-user-level'
            // }
          ]
        },
        {
          menuId: '4',
          title: '商品',
          icon: 'iconfont icon-casefile',
          list: [
            {
              menuId: '4-1',
              title: '商品分类',
              icon: '',
              routeName: 'shop-mall-sh-goods-category'
            },
            {
              menuId: '4-2',
              title: '品牌管理',
              isHide: false,
              icon: '',
              routeName: 'shop-mall-sh-brand'
            },
            {
              menuId: '4-3',
              title: '专题管理',
              isHide: false,
              icon: '',
              routeName: 'shop-mall-sh-topic'
            },
            {
              menuId: '4-4',
              title: '商品管理',
              isHide: false,
              icon: '',
              routeName: 'shop-mall-sh-goods'
            },
            {
              menuId: '4-5',
              title: '优惠券管理',
              isHide: false,
              icon: '',
              routeName: 'shop-mall-sh-coupon'
            }

          ]
        },
        {
          menuId: '5',
          title: '订单管理',
          icon: 'iconfont icon-enterprise',
          list: [
            {
              menuId: '5-1',
              title: '订单列表',
              icon: '',
              routeName: 'shop-mall-sh-order'
            }
          ]
        },
        {
          menuId: '6',
          title: '退货管理',
          icon: 'iconfont icon-enterprise',
          list: [
            {
              menuId: '6-1',
              title: '退货列表',
              icon: '',
              routeName: 'shop-mall-order-return'
            }
          ]
        },
        // {
        //   menuId: '6',
        //   title: '装修',
        //   icon: 'iconfont icon-swatche',
        //   routeName: 'sh-decoration'
        // },
        {
          menuId: '7',
          title: '版本',
          icon: 'iconfont icon-version',
          routeName: 'shop-mall-version'
        },
        {
          menuId: '9',
          title: '设置',
          icon: 'iconfont icon-setting',
          routeName: 'shop-mall-sh-config'
        }
      ]
    }
  }
}

export function sideMenuListSt (params) {
  const appMenuListJson = {
    'super-store': [
      {
        menuId: '1',
        title: '数据概况',
        icon: 'iconfont icon-overview',
        list: [
          {
            menuId: '1-1',
            title: '数据概况',
            icon: '',
            routeName: 'st-overview-data'
          }
        ]
      },
      {
        menuId: '2',
        title: '门店信息',
        icon: 'iconfont icon-book',
        list: [
          {
            menuId: '2-1',
            title: '门店信息',
            icon: '',
            routeName: 'st-store-info-index'
          }
        ]
      },
      {
        menuId: '3',
        title: '版本',
        icon: 'iconfont icon-version',
        list: [
          {
            menuId: '3-1',
            title: '版本',
            icon: '',
            routeName: 'st-version'
          }
        ]
      }
    ]
  }
  return {
    'code': 0,
    'result': {
      'length': 4,
      'items': (params && params.type) ? appMenuListJson[params.type] : []
    }
  }
}
// 模板页使用获取链接列表的相关接口

// 获取公告
export function getNoticeList (params) {
  return request({
    // url: requestUrl('/miniapp/getNoticeList'),
    url: requestUrl('/miniapp/msnoticeinfo/listnopage'),
    method: 'get',
    params: requestParam(params, 'get')
  })
}

// 获取文章分类
export function getArticleType (params) {
  return request({
    // url: requestUrl('/miniapp/getArticleType'),
    url: requestUrl('/miniapp/msarticlecategory/listnopage'),
    method: 'get',
    params: requestParam(params, 'get')
  })
}

// 获取文章
export function getArticleList (params) {
  return request({
    // url: requestUrl('/miniapp/getArticleList'),
    url: requestUrl('/miniapp/msarticleinfo/listnopage'),
    method: 'get',
    params: requestParam(params, 'get')
  })
}

// 获取产品
export function getProductList (params) {
  return request({
    // url: requestUrl('/miniapp/getProductList'),
    url: requestUrl('/miniapp/msproductinfo/listnopage'),
    method: 'get',
    params: requestParam(params, 'get')
  })
}

// 获取案例
export function getCaseList (params) {
  return request({
    // url: requestUrl('/miniapp/getCaseList'),
    url: requestUrl('/miniapp/mscaseinfo/listnopage'),
    method: 'get',
    params: requestParam(params, 'get')
  })
}

// 获取已经上传的图片
export function getImgList (params) {
  return request({
    url: requestUrl('/sys/attachment/list'),
    method: 'post',
    data: requestParam(params)
  })
}

// 获取已经上传的视频
export function getVideoList (params) {
  return request({
    url: requestUrl('/sys/attachment/list'),
    method: 'post',
    data: requestParam(params)
  })
}

// 获取企业详情
export function getCompanyDeta (id) {
  return request({
    url: requestUrl('/miniapp/mscompanyinfo/templateinfo' + `/${id}`),
    method: 'get',
    params: requestParam({}, 'get')
  })
}

// 获取企业信息列表
export function getCompanyList (params) {
  return request({
    url: requestUrl('/miniapp/mscompanyinfo/listnopage'),
    method: 'get',
    params: requestParam({}, 'get')
    // })
    // url: requestUrl('/miniapp/mscompanyinfo/listnopage'),
    // method: 'post',
    // data: requestParam(params)
  })
}

// 获取表单列表 getFormList
export function getFormList (params) {
  return request({
    url: requestUrl('/miniapp/msforminfo/listnopage'),
    method: 'get',
    params: requestParam({}, 'get')
  })
}

// 获取表单详情 getFormDetail
export function getFormDetail (params) {
  return request({
    // url: requestUrl('/miniapp/getFormDetail'),
    url: requestUrl('/miniapp/msfieldinfo/listnopage'),
    method: 'get',
    params: requestParam({}, 'get')
  })
}
